# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libplacebo
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.264.1
pkgrel=2
pkgdesc="Reusable library for GPU-accelerated video/image rendering primitives (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://code.videolan.org/videolan/libplacebo"
depends=("${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-libdovi"
         "${MINGW_PACKAGE_PREFIX}-shaderc"
         "${MINGW_PACKAGE_PREFIX}-spirv-cross"
         "${MINGW_PACKAGE_PREFIX}-vulkan")
makedepends=("git"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-python-glad"
             "${MINGW_PACKAGE_PREFIX}-python-jinja"
             "${MINGW_PACKAGE_PREFIX}-vulkan-headers")
license=('LGPL2.1')
source=(${url}/-/archive/v${pkgver}/${_realname}-v${pkgver}.tar.gz)
sha256sums=('9eb0c198f58d994f1c0d173dd37647d4d07d27972412c48ab758e984503c787b')

build() {
  [[ -d "${srcdir}"/build-shared-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-shared-${MSYSTEM}
  mkdir -p "${srcdir}"/build-shared-${MSYSTEM} && cd "${srcdir}"/build-shared-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup                   \
      --prefix="${MINGW_PREFIX}"  \
      --buildtype plain           \
      -Ddemos=false               \
      -Dtests=true                \
      -Dd3d11=enabled             \
      -Dlcms=enabled              \
      -Dlibdovi=enabled           \
      -Dshaderc=enabled           \
      -Dvulkan=enabled            \
      "../${_realname}-v${pkgver}"

  meson compile

  [[ -d "${srcdir}"/build-static-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-static-${MSYSTEM}
  mkdir -p "${srcdir}"/build-static-${MSYSTEM} && cd "${srcdir}"/build-static-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup                   \
      --prefix="${MINGW_PREFIX}"  \
      --buildtype plain           \
      -Ddemos=false               \
      -Dtests=false               \
      -Dd3d11=enabled             \
      -Dlcms=enabled              \
      -Dlibdovi=enabled           \
      -Dshaderc=enabled           \
      -Dvulkan=enabled            \
      --default-library=static    \
      --prefer-static             \
      "../${_realname}-v${pkgver}"

  meson compile
}

check() {
  cd "${srcdir}"/build-shared-${MSYSTEM}

  meson test
}

package() {
  cd "${srcdir}"/build-static-${MSYSTEM}
  DESTDIR="${pkgdir}" meson install

  cd "${srcdir}"/build-shared-${MSYSTEM}
  DESTDIR="${pkgdir}" meson install

  install -Dm644 "${srcdir}/${_realname}-v${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
